package com.my.serviceimpl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.my.bean.Production;
import com.my.bean.ResultPage;
import com.my.bean.VoPage;
import com.my.mapper.ProductionMapper;
import com.my.service.ProductionService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 产康可预约 服务实现类
 * </p>
 *
 * @author 冯政尚
 * @since 2018-08-25
 */
@Service
public class ProductionServiceImpl extends ServiceImpl<ProductionMapper, Production> implements ProductionService {



   /* public List<Production> selectProductionResultMap(){
        return productionMapper.selectProductionResultMap();
    }

    //批量添加
    public List<Production> bathInsert(){
        return productionMapper.bathInsert();
    }*/

    //查询所有
    public List<Production> selectProduction(){
        return baseMapper.selectProduction();
    }

    //实现分页查询
    @Override
    public ResultPage<Production> selectMyPage(Map map, String stat, VoPage voPage, long areaid,boolean admin) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1)*voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("stat", stat);
        List<Production> list = baseMapper.selectMyPage(map,paramMap,areaid,admin);
        Integer count = baseMapper.countMyPage(map,paramMap,areaid,admin);
        ResultPage<Production> resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }



    //修改 可预约变成不可预约
    public List<Production> selectProductionById(Long id){
        return baseMapper.selectProductionById(id);
    }

    @Override
    public String updateProductionState(Long id) {
        if(baseMapper.updateProductionState(id)>0){
            return  "修改成功";
        }
        return  "修改失败";
    }

    //修改可预约变成不可预约
    public List<Production> selectProductionById2(Long id){
        return baseMapper.selectProductionById2(id);
    }

    @Override
    public String updateProductionState2(Long id){
        if(baseMapper.updateProductionState2(id)>0){
            return "修改成功";

        }
        return "修改失败";
    }

    //根据状态查询可预约的
    public List<Production> selectByAppointmentId(Long id){
        return baseMapper.selectByAppointmentId(id);
    }

    @Override
    public ResultPage<Production> findProjectByHomeId(Long homeId, VoPage voPage, long areaid,boolean admin) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1)*voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("homeid", homeId);
        List<Production> list = baseMapper.findProjectByHomeId(paramMap,areaid,admin);
        Integer count = baseMapper.findProjectByHomeIdCount(paramMap,areaid,admin);
        ResultPage<Production> resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    @Override
    public ResultPage<Production> findProjectByHomeId(VoPage voPage, long areaid,boolean admin) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1)*voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        List<Production> list = baseMapper.findProjectAll(paramMap,areaid,admin);
        Integer count = baseMapper.findProjectAllCount(paramMap,areaid,admin);
        ResultPage<Production> resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }


}
